﻿using System;
using System.Collections.Generic;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Context;
using ZyGames.Framework.Game.Contract;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Service;
using System.Linq;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Script;
using ZyGames.DZPocker.Tools;
using ZyGames.Framework.Common.Serialization;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 设置界面
	/// </summary>
	public class Action10059 : BaseAction
	{
		private int userId;
		private string userInfoStr = "";
		private bool result = false;
		private string log = "";
		public Action10059(HttpGet actionGetter)
			: base((short)ActionType.DZApplyUserInfo, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("UserId", ref userId))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			var currentGameUser = GameTable.Current.GetUser(userId);
			if (currentGameUser == null)
			{
				Tool.WriteWarmingLine("消息10059玩家不存在");
				log = "查询异常";
				result = false;
				return true;
			}
			var headIcon = GameTable.Current.GetUserHeadIconByUserId(userId);
			var simpleUser = new SimpleUserDataWithDetailInfo() { UserId = userId, NickName = currentGameUser.NickName, HeadIcon = headIcon, Sex = currentGameUser.Sex, Sign = currentGameUser.Sign };
			userInfoStr = Convert.ToBase64String(ProtoBufUtils.Serialize(simpleUser));
			result = true;
			return true;
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(this.result);
			this.PushIntoStack(this.userInfoStr);
			this.PushIntoStack(this.log);
		}
	}
}
